﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;

namespace ERP.Classes
{
    public class cs_hmr_thongbaoInfo
    {
        private int _id_tb;
        private string _noidung;
        private int _nguoi_tb;
        private DateTime _ngay_tb;
        private string _ma_ct;
        private string _tieude;
        private int _nguoinhan;
        private bool _danhan;
        private string _ngaynhan;
        private string _ghichu;

        
        public cs_hmr_thongbaoInfo()
        {
            this._id_tb = 0;
            this._noidung = " ";
            this._nguoi_tb = 0;
            this._ngay_tb = Convert.ToDateTime("01/01/9999");
            this._ma_ct = " ";
            this._tieude = " ";
            this._nguoinhan = 0;
            this._danhan = false;
            this._ngaynhan = " ";
            this._ghichu = " ";

        }
        public int id_tb
        {
            get
            {
                return this._id_tb;
            }
            set
            {
                this._id_tb = value;
            }
        }
        public string noidung
        {
            get
            {
                return this._noidung;
            }
            set
            {
                this._noidung = value;
            }
        }
        public int nguoi_tb
        {
            get
            {
                return this._nguoi_tb;
            }
            set
            {
                this._nguoi_tb = value;
            }
        }
        public DateTime ngay_tb
        {
            get
            {
                return this._ngay_tb;
            }
            set
            {
                this._ngay_tb = value;
            }
        }
        public string ma_ct
        {
            get
            {
                return this._ma_ct;
            }
            set
            {
                this._ma_ct = value;
            }
        }
        public string tieude
        {
            get
            {
                return this._tieude;
            }
            set
            {
                this._tieude = value;
            }
        }
        public int nguoinhan
        {
            get
            {
                return this._nguoinhan;
            }
            set
            {
                this._nguoinhan = value;
            }
        }
        public bool danhan
        {
            get
            {
                return this._danhan;
            }
            set
            {
                this._danhan = value;
            }
        }
        public string ngaynhan
        {
            get
            {
                return this._ngaynhan;
            }
            set
            {
                this._ngaynhan = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[11];
            paraName[0] = "@id_tb";
            paraName[1] = "@noidung";
            paraName[2] = "@nguoi_tb";
            paraName[3] = "@ngay_tb";
            paraName[4] = "@ma_ct";
            paraName[5] = "@tieude";
            paraName[6] = "@nguoinhan";
            paraName[7] = "@danhan";
            paraName[8] = "@ngaynhan";
            paraName[9] = "@ghichu";
            paraName[10] = "@option";
            object[] paraValue = new object[11];
            paraValue[0] = this._id_tb;
            paraValue[1] = this._noidung;
            paraValue[2] = this._nguoi_tb;
            paraValue[3] = this._ngay_tb;
            paraValue[4] = this._ma_ct;
            paraValue[5] = this._tieude;
            paraValue[6] = this._nguoinhan;
            paraValue[7] = this._danhan;
            paraValue[8] = this._ngaynhan;
            paraValue[9] = this._ghichu;
            paraValue[10] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 11, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        public void KetDulieuVaoListview(ListView myList)
        {
            csListView list = new csListView();
            string[] fields = new string[10];
            fields[0] = "id_tb";
            fields[1] = "noidung";
            fields[2] = "nguoi_tb";
            fields[3] = "ngay_tb";
            fields[4] = "ma_ct";
            fields[5] = "tieude";
            fields[6] = "nguoinhan";
            fields[7] = "danhan";
            fields[8] = "ngaynhan";
            fields[9] = "ghichu";
            list.KetDulieu(myList, "HMR_THONGBAO", "", fields);
        }
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_HMR_THONGBAO", option);
        }

        public void ShowDataInCombo(ComboBox cbo, string condition)
        {
            csComboBox cb = new csComboBox("noidung", "id_tb");
            cb.KetDuLieu(cbo, "HMR_THONGBAO", condition);
        }

        public int ShowDataGrid(DataGrid datagrid, string condition)
        {
            csDataGrid grid = new csDataGrid();

            string[] header = new string[10];
            header[0] = "id_tb";
            header[1] = "noidung";
            header[2] = "nguoi_tb";
            header[3] = "ngay_tb";
            header[4] = "ma_ct";
            header[5] = "tieude";
            header[6] = "nguoinhan";
            header[7] = "danhan";
            header[8] = "ngaynhan";
            header[9] = "ghichu";

            string[] mappingname = new string[10];
            mappingname[0] = "id_tb";
            mappingname[1] = "noidung";
            mappingname[2] = "nguoi_tb";
            mappingname[3] = "ngay_tb";
            mappingname[4] = "ma_ct";
            mappingname[5] = "tieude";
            mappingname[6] = "nguoinhan";
            mappingname[7] = "danhan";
            mappingname[8] = "ngaynhan";
            mappingname[9] = "ghichu";

            int[] colwidth = new int[10];
            colwidth[0] = 12;
            colwidth[1] = 24000;
            colwidth[2] = 12;
            colwidth[3] = 24;
            colwidth[4] = 60;
            colwidth[5] = 1200;
            colwidth[6] = 12;
            colwidth[7] = 3;
            colwidth[8] = 30;
            colwidth[9] = 1200;
            csCSDL csdl = new csCSDL();
            return grid.CreateTableStyle("HMR_THONGBAO", datagrid, csdl.OpenTable("HMR_THONGBAO", condition), header, mappingname, colwidth, 10);
        }
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("HMR_THONGBAO", "");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_tb = Convert.ToInt32(ds.Tables[0].Rows[0]["id_tb"].ToString().Trim());
                this._noidung = ds.Tables[0].Rows[0]["noidung"].ToString().Trim();
                this._nguoi_tb = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoi_tb"].ToString().Trim());
                this._ngay_tb = Convert.ToDateTime(ds.Tables[0].Rows[0]["ngay_tb"].ToString().Trim());
                this._ma_ct = ds.Tables[0].Rows[0]["ma_ct"].ToString().Trim();
                this._tieude = ds.Tables[0].Rows[0]["tieude"].ToString().Trim();
                this._nguoinhan = Convert.ToInt32(ds.Tables[0].Rows[0]["nguoinhan"].ToString().Trim());
                this._danhan = Convert.ToBoolean(ds.Tables[0].Rows[0]["danhan"].ToString().Trim());
                this._ngaynhan = ds.Tables[0].Rows[0]["ngaynhan"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                return 1;
            }
            catch
            {
                return -1;
            }
        }
    }
}
